#include "clickedbtn.h"
#include "global.h"

#include <QVariant> // setProperty 函数需要使用到的头文件

ClickedBtn::ClickedBtn(QWidget* parent)
    : QPushButton(parent)
{
    setCursor(Qt::PointingHandCursor); // 设置光标为小手
}

ClickedBtn::~ClickedBtn(){}

//
void ClickedBtn::SetState(QString normal, QString hover, QString press){
    _normal = normal;
    _hover = hover;
    _press = press;
    setProperty("state", _normal);
    repolish(this);
    update();
}

// 鼠标的进入和离开
void ClickedBtn::enterEvent(QEvent* event){
    setProperty("state", _hover);
    repolish(this);
    update();
    QPushButton::enterEvent(event);
}
void ClickedBtn::leaveEvent(QEvent* event){
    setProperty("state", _normal);
    repolish(this);
    update();
    QPushButton::leaveEvent(event);
}

// 鼠标的按下和抬起
void ClickedBtn::mousePressEvent(QMouseEvent* event){
    setProperty("state", _press);
    repolish(this);
    update();
    QPushButton::mousePressEvent(event);
}
void ClickedBtn::mouseReleaseEvent(QMouseEvent* event){
    setProperty("state", _hover);
    repolish(this);
    update();
    QPushButton::mouseReleaseEvent(event);
}
